package com.xinfu.newproject.presenter;

import android.util.Log;

import com.xinfu.newproject.bean.login.PhoneBody;
import com.xinfu.newproject.bean.login.PhoneBean;
import com.xinfu.newproject.callback.MyCallBack;
import com.xinfu.newproject.model.login.PhoneModel;
import com.xinfu.newproject.view.IView;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.disposables.Disposable;

import static com.xinfu.newproject.activity.LoginActivity.FRAGMENT_THREE;
import static com.xinfu.newproject.activity.LoginActivity.FRAGMENT_TWO;

public class PhonePresenter {
    private IView.IPhoneView mIPhoneView;

    PhoneModel mPhoneModel;
    //  private LoginModel mPhoneModel;

    public PhonePresenter(IView.IPhoneView iPhoneView) {
        this.mIPhoneView = iPhoneView;
        mPhoneModel = new PhoneModel();
    }

    /**
     * 登录
     */
    public void phone() {
      /*  Map<String, String> paraMap =new HashMap<>();
        paraMap.put("userName",mIPhoneView.getUserName());
        paraMap.put("passWord",mIPhoneView.getPassWord());*/
        mIPhoneView.showProgress();

        PhoneBody phoneBody = new PhoneBody(mIPhoneView.getUserName());

        mPhoneModel.phone(phoneBody, new MyCallBack<PhoneBean>() {
            @Override
            public void onSuccess(PhoneBean phoneBean) {
                mIPhoneView.hideProgress();
                if (phoneBean.getCode() == 0) {
                    if (phoneBean.isSuccess()) {
                        mIPhoneView.toOtherActivity(FRAGMENT_TWO);
                    } else {
                        mIPhoneView.toOtherActivity(FRAGMENT_THREE);
                    }

                }
                mIPhoneView.showToast(phoneBean.getMessage());
                Log.i("testPhone", "success=" + phoneBean.isSuccess() + "code=" + phoneBean.getCode() + "message=" + phoneBean.getMessage() + "result=" + phoneBean.getResult());
            }

            @Override
            public void onError(String header, String message) {
                mIPhoneView.hideProgress();
                mIPhoneView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mIPhoneView.closeDispose(disposable);
            }
        });


      /*  mPhoneModel.login(loginBody, new MyCallBack.OnLoginListener() {
            @Override
            public void loginSuccess(UserLoginBean userLoginBean) {
                mIPhoneView.showToast(userLoginBean.getMessage());
            }
            @Override
            public void loginFailed(String header, String message) {
            }
            @Override
            public void dispose(Disposable disposable) {
                mIPhoneView.closeDispose(disposable);
            }
        });*/

    }


    private Map<String, String> createParaMap() {
        Map<String, String> paraMap = new HashMap<>();
        paraMap.put("userName", mIPhoneView.getUserName());
        return paraMap;
    }

}
